﻿using Base.Helper;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using System.Linq;

namespace Model
{
    public class cms_article_tab
    {

        private readonly EFContext _context;
        public cms_article_tab(EFContext context)
        {
            _context = context;
        }
        #region 
        [Key]
        /// <summary>
        /// id
        /// </summary>		
        public int id { get; set; }
        /// <summary>
        /// attr_name
        /// </summary>		
        public string tabName { get; set; }
        /// <summary>
        /// 标签分类
        /// </summary>		
        public int articleType { get; set; }
        /// <summary>
        /// 0系统 1自定义
        /// </summary>		
        public int tabType { get; set; }
        /// <summary>
        /// 用户
        /// </summary>		
        public int tabformUid { get; set; }

        #endregion

        #region  帮助方法

        public string QueryUserSelectTag(string tagId)
        {
            if (CString.IsEmpty(tagId)) return "";
            tagId = tagId.Trim().Trim(',');
            int[] intTagId = Array.ConvertAll(tagId.Split(","), s => int.Parse(s));
            var list = from s in _context.cms_article_tab
                       where s.tabType == 0 && s.articleType == 6 && intTagId.Contains(s.id)
                       select s;
            List<string> new_list = new List<string>();
            if (list.Count() > 0)
            {
                foreach (cms_article_tab item in list) { new_list.Add(item.tabName); }

                return string.Join(",", new_list.ToArray());
            }
            return "";
        }
        #endregion


    }
}
